<%--
  Created by IntelliJ IDEA.
  User: jqy
  Date: 2023/12/9
  Time: 17:21
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page import="java.sql.*" %>

<html>
<head>
    <title>student</title>
    <style>
        .box {
            width: 1000px;
            /* 超出部分隐藏 */
            overflow: hidden;
            margin: auto;
            display: flex;
            background-color: #E1E9EF;
        }

        .content {
            width: 600px;
            height: 600px;
            flex-shrink: 0;
        }

        .table11_3{
            width: 1000px;
            height: 600px;
        }
         .table11_3 table {
             margin:40px 20px;
             border:0;
         }
        .table11_3 th {
            background-color:#FF5675;
            color:#FFFFFF
        }
        .table11_3,.table11_3 th,.table11_3 td {
            font-size:0.95em;
            text-align:center;
            padding:4px;
            border-collapse:collapse;
        }
        .table11_3 th,.table11_3 td {
            border: 1px solid #fe2047;
            border-width:1px 0 1px 0;
            border:2px inset #ffffff;
        }
        .table11_3 tr {
            border: 1px solid #ffffff;
        }
        .table11_3 tr:nth-child(odd){
            background-color:#fec6d1;
        }
        .table11_3 tr:nth-child(even){
            background-color:#ffffff;
        }
    </style>
</head>
<body>

<section>
    <div class="box">
        <%
            Class.forName("com.mysql.jdbc.Driver");
            String url = "jdbc:mysql://localhost:3306/hospital";
            String name = "root";
            String password = "12345";
            request.setCharacterEncoding("UTF-8");
            Connection conn = DriverManager.getConnection(url, name, password);
            //Statement stmt = conn.createStatement();
            PreparedStatement stmt=null;
            String sql = new String();
            if (request.getParameter("Identity").equals("医生")) {
                sql = "select * from doctor WHERE doc_name = ?";
                stmt = conn.prepareStatement(sql);
                stmt.setString(1, request.getParameter("Doctorname"));
            }
            else if (request.getParameter("Identity").equals("护士")) {
                sql = "select * from nurse WHERE nur_name = ?";
                stmt = conn.prepareStatement(sql);
                stmt.setString(1, request.getParameter("Doctorname"));
            }
            ResultSet rs = stmt.executeQuery();
            String _no = new String();
            String _name = new String();
            String _zhicheng = new String();
            String _sex = new String();
            String _sect_no = new String();
            String sect_name = new String();
            int i = 0;
            while (rs.next()) {
                _no = rs.getString("doc_no");
                _name = rs.getString("doc_name");
                _zhicheng = rs.getString("doc_zhicheng");
                _sex = rs.getString("doc_sex");
                _sect_no = rs.getString("doc_sect_no");
                String asql = "SELECT section.sect_name FROM section WHERE sect_no = ?";
                PreparedStatement sstmt = conn.prepareStatement(asql);
                sstmt.setString(1, _sect_no);
                ResultSet rrs = sstmt.executeQuery();
                while (rrs.next()) {
                    sect_name = rrs.getString("sect_name");
                }
                rrs.close();
                sstmt.close();
                i++;
                String c = String.valueOf(i);
        %>
        <div id="<%=c%>" class="content">
            <table class=table11_3>
                <tr>
                    <td>
                        编号
                    </td>
                    <td>
                        姓名
                    </td>
                    <td>
                        职称
                    </td>
                    <td>
                        性别
                    </td>
                    <td>
                        科室名称
                    </td>
                </tr>
                <tr>
                    <td>
                        <%=_no%>
                    </td>
                    <td>
                        <%=_name%>
                    </td>
                    <td>
                        <%=_zhicheng%>
                    </td>
                    <td>
                        <%=_sex%>
                    </td>
                    <td>
                        <%=sect_name%>
                    </td>
                </tr>
            </table>
        </div>
        <%
            }
        %>

    </div>
</section>
<%
    for (int j = 1; j <= i; j++) {
        StringBuilder sb = new StringBuilder();
        sb.append("#").append(String.valueOf(j));
        String c = new String(sb);
%>
<p><a href="<%=c%>" id="nav1"><%=c%>
</a></p>
<%
    }
    rs.close();
    stmt.close();
    conn.close();
%>
</body>
</html>

